<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="主键" prop="id">-->
<!--        <el-input-->
<!--          v-model="queryParams.id"-->
<!--          placeholder="请输入主键"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="厂端id" prop="factoryId">
        <el-input
          v-model="queryParams.factoryId"
          placeholder="请输入厂端id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经销商id" prop="dealerId">
        <el-input
          v-model="queryParams.dealerId"
          placeholder="请输入经销商id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经销商名" prop="dealerName">
        <el-input
          v-model="queryParams.dealerName"
          placeholder="请输入经销商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="采购状态" prop="purchaseStatus">-->
<!--        <el-select v-model="queryParams.purchaseStatus" placeholder="请选择采购状态" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.part_purchase_status"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item label="采购数量" prop="wholePurchaseNumber">
        <el-input
          v-model="queryParams.wholePurchaseNumber"
          placeholder="请输入采购零件的数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="采购总价" prop="purchasePrice">
        <el-input
          v-model="queryParams.purchasePrice"
          placeholder="请输入采购的总价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付方式" prop="paymentMethod">
        <el-select v-model="queryParams.paymentMethod" placeholder="请选择支付方式" clearable>
          <el-option
            v-for="dict in dict.type.pay_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="仓库" prop="whseCode">
        <el-select v-model="queryParams.whseCode" placeholder="请选择仓库" clearable>
          <el-option
            v-for="dict in dict.type.warehouse_list"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="交货时间" prop="expectedDeliveryDate">
        <el-date-picker clearable
          v-model="queryParams.expectedDeliveryDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择期望交货时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="发运方式" prop="shipmentType">
        <el-select v-model="queryParams.shipmentType" placeholder="请选择发运方式" clearable>
          <el-option
            v-for="dict in dict.type.shipment_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="收货人" prop="receiver">
        <el-input
          v-model="queryParams.receiver"
          placeholder="请输入收货人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="telephone">
        <el-input
          v-model="queryParams.telephone"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核人id" prop="auditorId">
        <el-input
          v-model="queryParams.auditorId"
          placeholder="请输入审核人id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核人名" prop="auditorName">
        <el-input
          v-model="queryParams.auditorName"
          placeholder="请输入审核人名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核时间" prop="auditorTime">
        <el-date-picker clearable
          v-model="queryParams.auditorTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择审核时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['part:purchase:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['part:purchase:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['part:purchase:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['part:purchase:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="purchaseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" v-if="false"/>
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="厂端id" align="center" prop="factoryId" />
      <el-table-column label="经销商id" align="center" prop="dealerId" />
      <el-table-column label="经销商名称" align="center" prop="dealerName" />
      <el-table-column label="采购状态" align="center" prop="purchaseStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.part_purchase_status" :value="scope.row.purchaseStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="采购零件的数量" align="center" prop="wholePurchaseNumber" />
      <el-table-column label="采购的总价" align="center" prop="purchasePrice" />
      <el-table-column label="支付方式" align="center" prop="paymentMethod">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pay_type" :value="scope.row.paymentMethod"/>
        </template>
      </el-table-column>
      <el-table-column label="采购备注" align="center" prop="purchaseRemark" />
      <el-table-column label="仓库" align="center" prop="whseCode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.warehouse_list" :value="scope.row.whseCode"/>
        </template>
      </el-table-column>
      <el-table-column label="期望交货时间" align="center" prop="expectedDeliveryDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expectedDeliveryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发运方式" align="center" prop="shipmentType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.shipment_type" :value="scope.row.shipmentType"/>
        </template>
      </el-table-column>
      <el-table-column label="收货人" align="center" prop="receiver" />
      <el-table-column label="联系电话" align="center" prop="telephone" />
      <el-table-column label="地址" align="center" prop="address" />
      <el-table-column label="审核人id" align="center" prop="auditorId" />
      <el-table-column label="审核人名称" align="center" prop="auditorName" />
      <el-table-column label="审核时间" align="center" prop="auditorTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditorTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="PurchaseVehicle(scope.row)"
            v-hasPermi="['part:purchase:edit']"
          >订单配件</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['part:purchase:remove']"-->
<!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改零件采购对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="采购状态" prop="purchaseStatus">
          <el-select v-model="form.purchaseStatus" placeholder="请选择采购状态">
            <el-option
              v-for="dict in dict.type.part_purchase_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="采购零件的数量" prop="wholePurchaseNumber">
          <el-input v-model="form.wholePurchaseNumber" placeholder="请输入采购零件的数量" />
        </el-form-item>
        <el-form-item label="采购的总价" prop="purchasePrice">
          <el-input v-model="form.purchasePrice" placeholder="请输入采购的总价" />
        </el-form-item>
        <el-form-item label="支付方式" prop="paymentMethod">
          <el-select v-model="form.paymentMethod" placeholder="请选择支付方式">
            <el-option
              v-for="dict in dict.type.pay_type"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="采购备注" prop="purchaseRemark">
          <el-input v-model="form.purchaseRemark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="仓库" prop="whseCode">
          <el-select v-model="form.whseCode" placeholder="请选择仓库">
            <el-option
              v-for="dict in dict.type.warehouse_list"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="期望交货时间" prop="expectedDeliveryDate">
          <el-date-picker clearable
            v-model="form.expectedDeliveryDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择期望交货时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发运方式" prop="shipmentType">
          <el-select v-model="form.shipmentType" placeholder="请选择发运方式">
            <el-option
              v-for="dict in dict.type.shipment_type"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="收货人" prop="receiver">
          <el-input v-model="form.receiver" placeholder="请输入收货人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="telephone">
          <el-input v-model="form.telephone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址" />
        </el-form-item>
        <el-divider content-position="center">零件采购详细信息</el-divider>

        <el-table v-loading="loading" :data="dmsPartsPurchaseOrderDetailList" @selection-change="handleSelectionChange01">
          <el-table-column type="selection" width="55" align="center" v-if="title=='添加零件采购'"/>
          <el-table-column label="id" align="center" prop="id" />
          <el-table-column label="店端/厂端的库存" align="center" prop="inventoryType" />
          <el-table-column label="零件来源" align="center" prop="partSource">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.part_source" :value="scope.row.partSource"/>
            </template>
          </el-table-column>
          <el-table-column label="零件编码" align="center" prop="partNo" />
          <el-table-column label="零件名称" align="center" prop="partName" />
          <el-table-column label="零件类型" align="center" prop="partType">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.part_name" :value="scope.row.partType"/>
            </template>
          </el-table-column>
          <el-table-column label="零件状态" align="center" prop="partStatus">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.part_status" :value="scope.row.partStatus"/>
            </template>
          </el-table-column>
          <el-table-column label="网点单价" align="center" prop="outletPrice" />
          <el-table-column label="零售单价" align="center" prop="salePrice" />
          <el-table-column label="采购单价" align="center" prop="purchasePrice" />
          <el-table-column label="生效日期" align="center" prop="effectiveDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.effectiveDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="截止日期" align="center" prop="expirationDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.expirationDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="裸件长mm" align="center" prop="grossLength" />
          <el-table-column label="裸件宽mm" align="center" prop="grossWidth" />
          <el-table-column label="裸件高mm" align="center" prop="grossHeight" />
          <el-table-column label="包装长mm" align="center" prop="packageLength" />
          <el-table-column label="包装宽mm" align="center" prop="packageWidth" />
          <el-table-column label="包装高mm" align="center" prop="packageHeight" />
          <el-table-column label="存放长mm" align="center" prop="storeLength" />
          <el-table-column label="存放宽mm" align="center" prop="storeWidth" />
          <el-table-column label="存放高mm" align="center" prop="storeHeight" />
          <el-table-column label="裸件重量g" align="center" prop="grossWeight" />
          <el-table-column label="包装后重量g" align="center" prop="packageWeight" />
          <el-table-column label="体积" align="center" prop="volume" />
          <el-table-column label="是否可销售" align="center" prop="isSale">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.no_and_yes" :value="scope.row.isSale"/>
            </template>
          </el-table-column>
          <el-table-column label="是否可采购" align="center" prop="isPurchase">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.no_and_yes" :value="scope.row.isPurchase"/>
            </template>
          </el-table-column>
          <el-table-column label="是否排放件" align="center" prop="isEmission">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.no_and_yes" :value="scope.row.isEmission"/>
            </template>
          </el-table-column>
          <el-table-column label="是否安全件" align="center" prop="isSafety">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.no_and_yes" :value="scope.row.isSafety"/>
            </template>
          </el-table-column>
          <el-table-column label="是否防盗件" align="center" prop="isAntiTheft">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.no_and_yes" :value="scope.row.isAntiTheft"/>
            </template>
          </el-table-column>
          <el-table-column label="是否认证件" align="center" prop="isCertified">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.no_and_yes" :value="scope.row.isCertified"/>
            </template>
          </el-table-column>
          <el-table-column label="是否航空禁运件" align="center" prop="isAirEmbargo">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.no_and_yes" :value="scope.row.isAirEmbargo"/>
            </template>
          </el-table-column>
          <el-table-column label="厂端id" align="center" prop="factoryId" />
          <el-table-column label="厂端名称" align="center" prop="factoryName" />
          <el-table-column label="经销商id" align="center" prop="dealerId" />
          <el-table-column label="销售店名称" align="center" prop="dealerName" />
          <el-table-column label="经销商入库时间" align="center" prop="dealerLastStorageTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.dealerLastStorageTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="厂端出库时间" align="center" prop="factoryLastShipmentTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.factoryLastShipmentTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
        </el-table>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPurchase, getPurchase, delPurchase, addPurchase, updatePurchase, getPartsInfoByIds,PurchaseVehicleById } from "@/api/part/purchaseVehicle";
import {listInventory} from "@/api/part/inventory";

export default {
  name: "Purchase",
  dicts: ['pay_type', 'warehouse_list', 'part_purchase_status', 'shipment_type'],
  data() {
    return {
      //查询到的零件号
      orderDetailpartNos: [],
      // 零件采购详细表格数据
      dmsPartsPurchaseOrderDetailList: [],
      //新增采购单时选择的零件代码
      checkedDmsDealerWholePurchaseDetail: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedDmsPartsPurchaseOrderDetail: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 零件采购表格数据
      purchaseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        factoryId: null,
        dealerId: null,
        dealerName: null,
        purchaseStatus: null,
        wholePurchaseNumber: null,
        purchasePrice: null,
        paymentMethod: null,
        purchaseRemark: null,
        whseCode: null,
        expectedDeliveryDate: null,
        shipmentType: null,
        receiver: null,
        telephone: null,
        address: null,
        auditorId: null,
        auditorName: null,
        auditorTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        purchaseStatus: [
          { required: true, message: "采购状态不能为空", trigger: "change" }
        ],
        wholePurchaseNumber: [
          { required: true, message: "采购零件的数量不能为空", trigger: "blur" }
        ],
        purchasePrice: [
          { required: true, message: "采购的总价不能为空", trigger: "blur" }
        ],
        paymentMethod: [
          { required: true, message: "支付方式不能为空", trigger: "change" }
        ],
        whseCode: [
          { required: true, message: "仓库不能为空", trigger: "change" }
        ],
        expectedDeliveryDate: [
          { required: true, message: "期望交货时间不能为空", trigger: "blur" }
        ],
        shipmentType: [
          { required: true, message: "发运方式不能为空", trigger: "change" }
        ],
        receiver: [
          { required: true, message: "收货人不能为空", trigger: "blur" }
        ],
        telephone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
        address: [
          { required: true, message: "地址不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询零件采购列表 */
    getList() {
      this.loading = true;
      this.queryParams.purchaseStatus = 3;
      listPurchase(this.queryParams).then(response => {
        this.purchaseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        factoryId: null,
        dealerId: null,
        dealerName: null,
        purchaseStatus: null,
        wholePurchaseNumber: null,
        purchasePrice: null,
        paymentMethod: null,
        purchaseRemark: null,
        whseCode: null,
        expectedDeliveryDate: null,
        shipmentType: null,
        receiver: null,
        telephone: null,
        address: null,
        auditorId: null,
        auditorName: null,
        auditorTime: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null,
        createUserName: null,
        updateUserName: null,
        version: null,
        deleteFlag: null
      };
      this.dmsPartsPurchaseOrderDetailList = [];
      this.checkedDmsPartsPurchaseOrderDetail = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    // 多选框选中数据
    handleSelectionChange01(selection) {
      // this.ids = selection.map(item => item.id)
      this.checkedDmsDealerWholePurchaseDetail = selection.map(item => item.index)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加零件采购";
      //查询零件库存表
      this.getPartInventoryList();
    },
    getPartInventoryList(){
      this.loading = true;
      this.queryParams.inventoryType = "厂端";
      listInventory(this.queryParams).then(response => {
        this.dmsPartsPurchaseOrderDetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 订单配件按钮 */
    PurchaseVehicle(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否为采购订单"' + ids + '"配件？').then(function() {
        return PurchaseVehicleById(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("配件成功");
      }).catch(() => {});
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPurchase(id).then(response => {
        this.form = response.data;
        // this.dmsPartsPurchaseOrderDetailList = response.data.dmsPartsPurchaseOrderDetailList;
        this.orderDetailpartNos = response.data.dmsPartsPurchaseOrderDetailList.map(item => item.partNo);
        console.log(this.orderDetailpartNos)
        this.open = true;
        this.title = "修改零件采购";
        this.getPartInventoryByIds(this.orderDetailpartNos);
      });
    },
    getPartInventoryByIds(orderDetailpartNos){
      console.log(orderDetailpartNos)
      this.loading = true;
      getPartsInfoByIds(orderDetailpartNos).then(response => {
        this.dmsPartsPurchaseOrderDetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            //把展示的数据都提交（不支持更改）
            this.form.dmsPartsPurchaseOrderDetailList = this.dmsPartsPurchaseOrderDetailList;
            updatePurchase(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            const checkedDmsDealerWholePurchaseDetail = this.checkedDmsDealerWholePurchaseDetail;
            this.form.dmsPartsPurchaseOrderDetailList = this.dmsPartsPurchaseOrderDetailList.filter(function(item) {
              return checkedDmsDealerWholePurchaseDetail.indexOf(item.index) != -1
            });
            addPurchase(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除零件采购编号为"' + ids + '"的数据项？').then(function() {
        return delPurchase(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
	/** 零件采购详细序号 */
    rowDmsPartsPurchaseOrderDetailIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 零件采购详细添加按钮操作 */
    handleAddDmsPartsPurchaseOrderDetail() {
      let obj = {};
      obj.partNo = "";
      obj.remark = "";
      this.dmsPartsPurchaseOrderDetailList.push(obj);
    },
    /** 零件采购详细删除按钮操作 */
    handleDeleteDmsPartsPurchaseOrderDetail() {
      if (this.checkedDmsPartsPurchaseOrderDetail.length == 0) {
        this.$modal.msgError("请先选择要删除的零件采购详细数据");
      } else {
        const dmsPartsPurchaseOrderDetailList = this.dmsPartsPurchaseOrderDetailList;
        const checkedDmsPartsPurchaseOrderDetail = this.checkedDmsPartsPurchaseOrderDetail;
        this.dmsPartsPurchaseOrderDetailList = dmsPartsPurchaseOrderDetailList.filter(function(item) {
          return checkedDmsPartsPurchaseOrderDetail.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleDmsPartsPurchaseOrderDetailSelectionChange(selection) {
      this.checkedDmsPartsPurchaseOrderDetail = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('part/purchase/export', {
        ...this.queryParams
      }, `purchase_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
